package com.CST.controller.ys;

import com.CST.common.api.ResultObject;
import com.CST.dto.ys.AppealDTO;
import com.CST.dto.ys.DetailDTO;
import com.CST.dto.ys.YsDetailDTO;
import com.CST.service.ys.YsAppealRecordService;
import com.CST.service.ys.YsAssetDetailService;
import com.CST.vo.ys.AssetDetailVO;
import com.CST.vo.ys.YsAssetDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ellen
 * @since 2023-04-21
 */
@RestController
@RequestMapping("/ysAssetDetail")
@Api(tags = "管理资产执行明细")
public class YsAssetDetailController {
    private final YsAssetDetailService service;
    private final YsAppealRecordService recordService;
    public YsAssetDetailController(YsAssetDetailService service, YsAppealRecordService recordService) {
        this.service = service;
        this.recordService = recordService;
    }
    @ApiOperation("分页管理资产预算执行明细查询")
    @PostMapping("/listAssetInfo")
    public ResultObject<YsAssetDetailVO> listAssetInfo(@RequestBody YsDetailDTO dto ){
        return ResultObject.success(service.listAssetInfo(dto));
    }

    @ApiOperation("管理资产预算执行明细导出")
    @PostMapping("/exportManageAssetList")
    public ResultObject<String> exportManageAssetList(@RequestBody YsDetailDTO dto, HttpServletResponse response){
        return ResultObject.success(service.exportManageAssetList(dto,response));
    }

    @ApiOperation("申诉回显，管理资产预算执行明细")
    @PostMapping("/get_obj")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "num",value = "编码"),
            @ApiImplicitParam(name = "yard",value = "院区 1三香，2浒关"),
    })
    public ResultObject<AssetDetailVO> getAssetByNum(@RequestBody DetailDTO params) {
        return ResultObject.success(service.getAssetByNum(params.getNum(),params.getYard()));
    }

    @ApiOperation("添加申诉")
    @PostMapping("/add")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "num",value = "预算明细编码,唯一确定一条申诉记录",required = true),
            @ApiImplicitParam(name = "yard",value = "预算明细院区,唯一确定一条申诉记录"),
            @ApiImplicitParam(name = "memo",value = "备注"),
            @ApiImplicitParam(name = "file",value = "文件ID 数组")
    })
    public ResultObject<Integer> addAppeal(@RequestBody AppealDTO dto, HttpServletRequest request) throws IOException {
        dto.setSource(3);
        return ResultObject.success(recordService.addAppeal(dto,request));
    }


}
